﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;

using Cookbook.Common;

namespace Cookbook.Services.Core.Persistency.Common
{
    public class PagedEnumerable<T> : IPagedEnumerable<T>
    {
        private readonly IEnumerable<T> innerEnumerable;

        public PagedEnumerable(IQueryable<T> queryable, int pageNumber, int pageSize)
        {
            innerEnumerable = queryable.TakePage(pageNumber, pageSize);
            Total = queryable.Count();
        }

        public PagedEnumerable(IEnumerable<T> enumerable, int total)
        {
            innerEnumerable = enumerable;
            Total = total;
        }

        public int Total { get; private set; }

        public IEnumerator<T> GetEnumerator()
        {
            return innerEnumerable.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
